from rest_framework import viewsets
from .serializers import UserSeralizer
from .models import User

from .filter import UserFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter
from utils.CustomPageNumberPagination import CustomPageNumberPagination
from django.db.models import F
class UserViewSet(viewsets.ModelViewSet):
    '''创建用户视图'''
    queryset = User.objects.all().order_by(F('id').asc())  # 强制按照 id 升序排序
    serializer_class = UserSeralizer
    filter_backends = [DjangoFilterBackend,OrderingFilter]
    filterset_class = UserFilter
    ordering_fields =['id']
    pagination_class = CustomPageNumberPagination

